package cn.itsource.org.service.impl;

import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartmentMapper;
import cn.itsource.org.query.DepartmentQuery;
import cn.itsource.org.service.IDepartmentService;
import cn.itsource.utli.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class DepartmentServiceImpl implements IDepartmentService {
    /**
     * 注入业务实现类
     */
    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 新增
     * @param department
     */
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    /**
     * 修改
     * @param department
     */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Department queryById(Long id) {
        return departmentMapper.queryById(id);
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Department> queryAll() {
        return departmentMapper.queryAll();
    }

    /**
     * 高级，分页查询
     * @param query
     * @return
     */
    @Override
    public PageInfo<Department> queryPage(DepartmentQuery query) {
        //总条数
        Long count = departmentMapper.count(query);
        List<Department> list = departmentMapper.queryDate(query);
        return new PageInfo<>(count,list);
    }

    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void patchDel(Long[] ids) {
        departmentMapper.patchDel(ids);
    }

    /**
     * 获取部门树的方法
     * @return
     */
    @Override
    public List<Department> getDeptTree() {

        return departmentMapper.getDeptTree();
    }



}
